package jmine.tec.database.pack;

import bancosys.tec.exception.LocalizedMessageHolder;
import bancosys.tec.exception.MessageCreator;
import bancosys.tec.exception.MessageCreatorHelper;

/**
 * Armazena as mensagens referentes ao processo de empacotamento
 * 
 * @author lundberg
 */
public enum PackingMessages implements MessageCreator {

    IO_EXCEPTION(0, "jmine.tec.database.pack.io.exception"),

    CONFLICTING_ENTITY_TYPE(3, "jmine.tec.database.pack.conflicting.entity.type");

    public static final String DEFAULT_BUNDLE = "jmine-tec-services-messages";

    private final String bundle;

    private final String key;

    private final int nargs;

    /**
     * Construtor
     * 
     * @param nargs nargs
     * @param key key
     */
    private PackingMessages(int nargs, String key) {
        this(DEFAULT_BUNDLE, key, nargs);
    }

    /**
     * Construtor
     * 
     * @param bundle bundle
     * @param key key
     * @param nargs nargs
     */
    private PackingMessages(String bundle, String key, int nargs) {
        this.bundle = bundle;
        this.key = key;
        this.nargs = nargs;
    }

    /**
     * Cria um message holder de acordo com os argumentos
     * 
     * @param arguments arguments
     * @return message holder
     */
    public LocalizedMessageHolder create(Object... arguments) {
        return MessageCreatorHelper.create(this.bundle, this.key, this.nargs, arguments);
    }

    /**
     * {@inheritDoc}
     */
    public int getExpectedArguments() {
        return this.nargs;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "MessageCreator: bundle=" + this.bundle + " key=" + this.key;
    }
}
